package OrdersSystem;

//import java.util.ArrayList;

//import OrdersSystem.DataBase;
import java.util.ArrayList;

import OrdersSystem.*;

public class DBSystemComm {


	//private ArrayList<Order> orders;
	
	/*public ArrayList<Order> getOrders(int customerID)
	{
		private ArrayList<Order> orders; // made this local
		ArrayList<Order> customerOrders = new ArrayList<Order>();
		
		for(Order order : orders) {
			if(order.getCustomerID() == customerID) {
				customerOrders.add(order);
			}
		}
		return customerOrders;
	}*/
	
	// attributes
	private  static DataBase db;
	
	// constructors
	public DBSystemComm() {
	    db = new DataBase();
	}
	
	// mutators
	public void storeData(Order newOrder) {  // stores a new order into the database
		//System.out.println("NewOrder = "+newOrder.getOrderID());
		db.storeOrder(newOrder);
	}
	
	// accessors
	public Order getOrder(int orderID) {  // get an order Object based on orderID
		return db.retrieveOrderByOrderId(orderID);
	}
	
	public ArrayList<Order> getOrders(int customerID) { // get all orders based on customerID
		return db.retrieveOrderByCustomerID(customerID);
	}
	
	public ArrayList<Order> getAllOrders() {
		return db.retrieveAllOrders();
	}
	
	public UserAlert getAlertByID(int alertID) { // get an UserAlert Object based on alertID
		return db.retrieveUserAlertByAlertId(alertID);
	}
	/*
	public ArrayList<UserAlert> getAlertByUser(int userID) { // get UserAlert Objects based on userID
		return db.retrieveAlertsByUserID(userID);
	}
	*/
	
	public RegisteredUser getUser(int userID) { // get a Customer Object based on userID
		return db.retrieveUser(userID);
	}

	
	public int getLastOrderID() {       // used by orderID generators
		return db.lastStoredOrderId();
	}
	
	public ContactDetails getContactDetails(int userID) {
		return db.retrieveContactDetails(userID);
	}
}
